<template>
    <div class="icons">
        <swiper :options="swiperOption">
            <swiper-slide v-for="(page,index) of pages" :key="index">
                <div class="icon" v-for="item of page" :key="item.id">
                    <div class="icon-img">
                        <img class="icon-img-content" :src="item.imgUrl" alt="">
                    </div>
                    <p class="icon-desc">{{item.desc}}</p>
                </div>
            </swiper-slide>
            <!-- <swiper-slide >
                <div class="icon">
                    <div class="icon-img">
                        <img class="icon-img-content" src="https://imgs.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
                    </div>
                    <p class="icon-desc">热门景点</p>
                </div>
            </swiper-slide> -->
        </swiper>
    
    </div>
</template>
<script>
export default {
  namde: 'HomeIcons',
  props: {
      iconList:Array
  },
  data () {
      return {
          swiperOption: {
              loop : false,
              autoplay:false
          },
        //   iconList:[{
        //       id:'001',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        //       desc:'热门景点'
              
        //   },{
        //       id:'002',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1804/ed/cf572be30fc32f02.png',
        //       desc:'Q+精选'
        //   },{
        //       id:'003',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1803/47/c2b659e048b11602.png',
        //       desc:'主题乐园'
        //   },{
        //       id:'004',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1803/75/eca3ce656c886502.png',
        //       desc:'漂流'
        //   },{
        //       id:'005',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1803/17/99402a22ce4af302.png',
        //       desc:'西湖'
        //   },{
        //       id:'006',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1803/6a/45f595250c73d102.png',
        //       desc:'夏日玩水'
        //   },{
        //       id:'007',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png',
        //       desc:'大宋千古情'
        //   },{
        //       id:'008',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png',
        //       desc:'杭州必游'
        //   },{
        //       id:'009',
        //       imgUrl:'https://imgs.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png',
        //       desc:'一日游'
        //   }
              
        //   ]      
    }
  },
  computed:{
      // 自动化 page 翻页
      pages () {
          const pages = []
          this.iconList.forEach((item,index) => {
              const page = Math.floor(index / 8)
              if(!pages[page]){
                  pages[page] = []
              }
              pages[page].push(item)
          })
          return pages

      }
  }
}
</script>
<style lang='stylus' scoped>
@import "~styles/varibles.styl"
@import "~styles/mixins.styl"
//占位 宽高比2:1
.icons >>> .swiper-container
    overflow: hidden
    width:100%
    height:0
    padding-bottom:50%
.icons
    margin-top:.1rem
    .icon
        position:relative
        overflow: hidden
        width:25%
        height:0
        float:left
        padding-bottom:25%
        .icon-img
            position:absolute
            top:0
            left:0
            right:0
            bottom:.44rem
            box-sizing:border-box
            padding:.1rem 
            .icon-img-content
                display:block
                margin:0 auto
                height:100%
        .icon-desc
            position:absolute           
            left:0
            right:0
            bottom:0
            height:.44rem
            line-height:.44rem
            color:$darkTextColor
            text-align:center
            ellipsis()

</style>
